Skip to content

feat(ai): a context pack's related list takes where / orderBy / limit (ADR-0160 row 11) - #37354

Merged
objectstack-fleet[bot] merged 8 commits into
mainfrom
claude/issue-37203-related-where-orderby-limit
Nov 26, 2026
Merged

objectstack-fleet[bot] merged 8 commits into
mainfrom
claude/issue-37203-related-where-orderby-limit

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #37203

Clause-②: yes
Metadata-protocol: added
Skills-docs: follow-up #37177

维护者速读

  • 用户能看到什么变化:AI 读取记录资料包时,关联列表可以按作者写的条件筛选、排序并限制条数;条件或排序用到提问人不能查询的字段时,这一段被省略并附一句「部分资料对你不可见」,不再整次报错。
  • 为什么做:记录范围 AI 问询专题的第 11 行(关联列表的筛选和排序),按维护者已同意的设计修订实现。
  • 出错会怎样:最坏是某个关联段落被省略或条数不对,AI 回答少了资料;不会多给提问人无权看的数据;撤回此 PR 即恢复原行为。
  • 要你做什么:无。

What changes

Spec (packages/spec/src/ai/ai-context.zod.ts). A related entry gains three optional keys, per ADR-0160 D1 (second amendment):

  • where: the object filter form on the child's own fields, held to AI_CONTEXT_WHERE_OPERATORS ($eq $ne $in $nin $gt $gte $lt $lte $null $exists) joined by $and / $or. A bare value is $eq. Refused at parse: any other operator, a dotted path, a condition on a lookup's target, { $field }, a $now anchor, a formula/object comparand, and a comparand that is one whole brace placeholder (matched by FILTER_TOKEN_WRAPPED_RE). Built as FilterConditionSchema plus one refinement walk, so the base form's own comparand refusals still apply.
  • orderBy: SortNodeSchema[] ({ field, order }, direction refused by name), with the field held to a snake_case own-field name.
  • limit: positive integer up to AI_CONTEXT_MAX_RELATED_ROWS (20). This is the one number. RECORD_CONTEXT_RELATED_MAX_ROWS in the service now reads it (ADR-0160 row 11: "the schema that bounds limit and the service that cuts the list read one number").
  • aiContextWhereFields(where): lists the fields a where names. The service and the lint rule both use it.
  • Near-miss aliases: filter → where, sort / sortBy → orderBy. The schema-level guidance.filter now points at the entry's where.

Render service (packages/services/service-record-context).

  • The one capped child query is where: { $and: [linkFilter, entry.where] }, with orderBy and limit: (entry.limit ?? cap) + 1. A cut at limit is marked truncated and stated (related_truncated). Still one query.
  • Before that query, each where / orderBy field is judged. A field the child's published definition lacks leaves the section out with nothing stated (ADR point 20). A field the caller cannot query on drops the section with the one not_visible statement, and the field is never named (D3, point 19). Neither case refuses the call.
  • "Cannot query on" is the door's new optional queryableFieldsOf (the security service's getQueryableFields). Without that answer, the contract's fallback applies (ISecurityService.getQueryableFields): the field must be served, must not be withheld (fieldVisibilityOf), and must declare no maskingRule. A probe that throws drops the section with the statement.
  • Triage row 7154563681 on the card (a related child that this caller is not served is left out, not refused) is not in this PR. It was implemented and then reverted in aa76b901b, because turning it on flips the real-kernel parity pin in packages/runtime (landed in test(runtime): get_record_context answers one caller with the same bytes on the /mcp and stdio doors over a real kernel #37350, case titled "[today; ADR-0160 as amended says left out and stated]"), and packages/runtime is fenced here. Today's behaviour (the whole call is refused) is unchanged. It moves to a follow-up card.
  • The read set (recordContextReadSet / planObjectsOf) does not change (D4), and a test pins it with and without the keys.

Author surfaces (packages/lint/src/validate-ai-context.ts). This extends the #37176 rule rather than adding a validator. A where or orderBy field the child does not define is reported as ai-context-field-unknown (warning) at save and by os validate, and the message says the list is left out.

Review delta S1/S2 (contract record 7177225249, on bb0107c).

  • S1: AI_CONTEXT_WHERE_MAX_DEPTH (32) bounds $and / $or nesting in where at parse, refused at the list that would carry a condition past it. aiContextWhereFields walks to that same constant, so every field of a where that parsed is judged by the service and the lint rule. A test pins the bound: 32 parses and names the innermost field, 33 is refused once.
  • S2: an orderBy field the child's sortability projection calls unsortable (resolveObjectSortability: a formula, or sortable: false) is an author defect. The executor leaves the section out and states nothing, matching the "field the definition lacks" arm and ADR D1, instead of letting the door refuse the whole call with INVALID_SORT. validateAiContext reports it at save and by os validate as the new warning ai-context-sort-field-unsortable, with an os explain entry. HTTP door, read only (runtime is fenced): recordContextMembers → bridge.query → callData('query') → protocol.findData → assertSortFieldsExist refuses it with 400 INVALID_SORT too (formula by the unmaterialized-type verdict, sortable: false by assertSortFieldsAreOffered), so before this fix both transports refused the call. After it, neither door is asked.

Liveness, example, generated. liveness/ai_context.json gains related.where, related.orderBy.{field,order} and related.limit. The showcase KIND_COVERAGE pack showcase_project_brief now carries open tasks filtered by status $ne done, ordered by due_date, limit: 10. Regenerated: dropped-refinements.baseline.json (the where walk and the orderBy field check are refinements JSON Schema cannot carry; the build printed these rows), authorable-surface, api-surface, export-origins, declaration-map, reference docs, state-counts.

Tests

Local runs (final head bb0107c; the derived gate sweep re-run on bb0107c)
  • pnpm --filter @objectstack/service-record-context test: 2 files, 99 tests passed. The new describe block "a related list's where, orderBy and limit" has 18 cases.
  • pnpm --filter @objectstack/spec exec vitest run src/ai/ai-context.zod.test.ts: 23 passed (parse admits and refuses every bullet of What 1, and the nesting bound).
  • pnpm --filter @objectstack/lint exec vitest run src/validate-ai-context.test.ts: 18 passed. Whole package pnpm --filter @objectstack/lint test: 235 files, 9633 tests passed.
  • pnpm --filter @objectstack/mcp exec vitest run src/mcp-record-context-tools.test.ts (read-only run of the 记录 AI 问询 5:资料包类型 ai_context、渲染服务与 get_record_context 工具(MCP) #37140 parity harness against the rebuilt service, at 16b86ef): 14 passed. CI Test Core at bb0107c runs it and the runtime real-kernel harness: green.
  • Typecheck: @objectstack/spec, @objectstack/service-record-context and @objectstack/lint all exit 0.
  • pnpm --filter @objectstack/spec check:generated: all 14 artifacts up to date.

Ablations: five, each through scripts/ablation-replace.mjs with the blob restored to HEAD. Each suite imports src, so there is no dist step.

  1. Skip queryableAmong: 6 cases red (the four unqueryable cases, the masking fallback, the throwing probe).
  2. Drop the $and join: 4 cases red, including "no where reaches another root's rows".
  3. S2, skip the executor's sortability check: 2 cases red (sortable: false, formula), the door's INVALID_SORT reached.
  4. S1, drop the parse depth bound: 1 case red (the bound test).
  5. S2, skip the lint verdict: 2 cases red (the rule test and its save-door family). A first attempt was refused by the tool as a no-op (ambiguous replacement) and re-run with a unique one.

Acceptance notes

  • Parity on both transports with a where pack is not pinned here. The 记录 AI 问询 5:资料包类型 ai_context、渲染服务与 get_record_context 工具(MCP) #37140 harness is packages/mcp/src/mcp-record-context-tools.test.ts, which was fenced for this PR while sibling 37140 跟进:get_record_context 在运行时 HTTP 通道上用真执行器测一遍(含拒绝) #37175 was in flight in packages/runtime/** and packages/mcp/**. Both doors hand the one executor a door whose query passes the options through (recordContextMembers, the stdio bridge's query already takes orderBy), and the existing harness runs green against this build. The pin is a follow-up for the report.
  • Neither MCP door hands queryableFieldsOf yet, so on real doors the contract fallback decides (masking-declared, hidden and withheld fields count as not queryable). A field that the security service's answer would exclude but the fallback admits (an agent acting on someone's behalf, or a computed field reading a hidden one) still reaches the engine guard, and the guard refuses the call. This is reported as a finding for the door lane.
  • Studio's ContextPackRelatedEntries does not offer the three keys yet; it preserves them on edit (note 7168171718). That goes to 记录 AI 问询 7:在 Studio 里编辑资料包(ai_context 表单与作者界面) #37143.
  • RecordContextNoteKind's doc line still says related_truncated is "cut at the row cap". It now also fires at limit. This is spec prose outside the claim's one spec file and is left as is.
  • A door whose own page cap is below limit + 1 cuts silently. That is pre-existing for the cap too, and left as is.
  • where nesting is bounded (S1). No bound on the number of conditions or $in members was set; ADR row 11 allows one, but none was needed.

Verification

Two-minute check: pnpm --filter @objectstack/service-record-context exec vitest run src/__tests__/record-context-tools.test.ts. Expect it green, with the "a related list's where, orderBy and limit" block green.

Read first: (1) record-context-tools.ts, the 4b block that judges queried fields before relatedPlans.push, and the $and query; (2) ai-context.zod.ts, checkRelatedWhere.


Generated by Claude Code

@github-actions github-actions Bot added size/xl documentation Improvements or additions to documentation protocol:ai tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 3 package(s): @objectstack/lint, @objectstack/service-record-context, @objectstack/spec, touching 32 documentable anchor(s). ⚠️ 9 changed file(s) yielded no anchor (packages/lint/src/index.ts, packages/spec/api-surface/ai.json, packages/spec/authorable-surface/ai.json, …), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

29 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json d0088bbb8fec784e3a8e6d6b9e564ccb3e14f6eb.

⛔ 6 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 9 changed file(s) yielded no anchor (packages/lint/src/index.ts, packages/spec/api-surface/ai.json, packages/spec/authorable-surface/ai.json, …) — pages documenting those are invisible to this run
  • 6 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 176 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json d0088bbb8fec784e3a8e6d6b9e564ccb3e14f6eb → packageMentionDocs.

Which tree this was computed on

This run read content/docs from b1ce322417d949f19f2b9da92a85cbc268e02a0e — the merge of head bb0107ccadaab70025c410545408414395527a26 into base d0088bbb8fec784e3a8e6d6b9e564ccb3e14f6eb, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin b1ce322417d949f19f2b9da92a85cbc268e02a0e && git checkout b1ce322417d949f19f2b9da92a85cbc268e02a0e
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin d0088bbb8fec784e3a8e6d6b9e564ccb3e14f6eb bb0107ccadaab70025c410545408414395527a26 && git checkout -B drift-repro d0088bbb8fec784e3a8e6d6b9e564ccb3e14f6eb && git merge --no-ff bb0107ccadaab70025c410545408414395527a26

node scripts/docs-audit/affected-docs.mjs --json d0088bbb8fec784e3a8e6d6b9e564ccb3e14f6eb

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs d0088bbb8fec784e3a8e6d6b9e564ccb3e14f6eb → pass the list as
args.docs, on the commit named under Which tree this was computed on.

…78 schemas, 1210 sites)

Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
Co-authored-by: Claude <noreply@anthropic.com>
…le-call refusal out of this PR

The amended left-out behaviour flips a pin in packages/runtime (the real-kernel
parity harness), which is outside this PR's file surface; it goes to its own
change with that pin.

Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/l and removed size/xl labels Nov 25, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head aa76b90 · 2026-11-25T23:05Z

The seat runs the at-tier contract review of this head through an isolated sub-agent; L1 is the seat's own.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: aa76b901be459a8271b412ad9fcb099024a7fb33
Local-runs: none
Scope: packages/spec/src/ai/ai-context.zod.ts + packages/services/service-record-context/src/record-context-tools.ts, packages/services/service-record-context/src/door.ts, packages/lint/src/validate-ai-context.ts

Inputs read: card #37203 (body and all 8 comments), PR #37354 body and file list (21 files), the net diff against main, the check-runs on this head (no failure; every required run success or skipped). Read to judge, not reviewed: docs/adr/0160-record-scoped-ai-inquiry.md (D1, D3, D4, points 13 to 21, row 11), packages/spec/src/data/filter.zod.ts, packages/spec/src/data/query.zod.ts, packages/spec/src/data/context-tokens.zod.ts, packages/spec/src/contracts/security-service.ts, packages/runtime/src/domains/mcp.ts#recordContextMembers, packages/mcp/src/stdio-data-bridge.ts.

① Derived judgments

  • related[] accept set widened by three optional keys (where, orderBy, limit); a pack without them parses and reads exactly as before. Right: ADR-0160 row 11, Metadata-protocol: added.
  • where is FilterConditionSchema plus one refinement walk, so it is a strict subset of the object filter form and the base form's comparand refusals still run. Read against ADR D1: the ten operators and $and / $or admitted; $not, every other $ key, a dotted key, a nested condition on a lookup's target, { $field }, $now, an object comparand, a whole {token} string (also as an $in / $nin member), a nested list and an empty operator map are each refused; a bare value is $eq; a string that only contains braces stays a literal. Right.
  • orderBy is SortNodeSchema[] with .min(1) and an own-field name check. orderBy: [] is refused, which the ADR's words do not state; an empty order means nothing, so right.
  • limit is an integer from 1 to AI_CONTEXT_MAX_RELATED_ROWS (20), and RECORD_CONTEXT_RELATED_MAX_ROWS now reads that constant. Right: point 14, one number. The service constant's type widens from the literal 20 to number; additive.
  • The aliases filter, sort, sortBy change a refusal's message only (the object was already strict). The schema-level guidance.filter text now points at the entry's where. Right.
  • New public exports of @objectstack/spec/ai: AI_CONTEXT_MAX_RELATED_ROWS, AI_CONTEXT_WHERE_OPERATORS, AI_CONTEXT_WHERE_COMBINATORS, aiContextWhereFields, AiContextRelatedWhereSchema and its two types. Additive; api-surface and export-origins moved with them and their gates are green.
  • RecordContextDoor.query takes an optional orderBy, and the door gains the optional queryableFieldsOf. Additive for a door implementer. Both in-tree doors pass query options through unchanged (read in recordContextMembers and the stdio bridge's query), so orderBy reaches the engine.
  • Lint: ai-context-field-unknown now also fires for a where / orderBy field the child lacks. No existing pack can carry those keys, so no existing pack gains a warning. Right.
  • The published JSON Schema for where and orderBy is wider than the Zod type; the new sites are in dropped-refinements.baseline.json and the gate is green. Right: new rules entering the ledger, no existing exemption widened.
  • The read set is unchanged: planObjectsOf takes nothing from the three keys (D4). Right.

② Semver level

minor on @objectstack/spec, @objectstack/service-record-context and @objectstack/lint. The diff adds authorable keys (Metadata-protocol: added, which takes at least minor on each package it moves) and removes or narrows nothing an author could write before. Check Changeset is success.
Clause-②: yes. The line stands in the PR body and in the changeset body, with no arm, and matches the diff.

③ Boundary flags

  • SQL push-down: holds. where, orderBy and limit all go into the one child query ($and with the link filter, limit + 1 probe). No new id materialisation and no in-app join, filter or sort. The added probes (queryableFieldsOf, fieldVisibilityOf) are metadata reads, at most one per related entry.
  • open_questions: none in the report.
  • Dev flag, parity acceptance PARTIAL: the card's line "same answer on MCP stdio and HTTP" has no where-pack case, because packages/mcp and packages/runtime were fenced. Accepted as carried, not as met. Escalated to the seat: the parity case needs a card before this PR closes ai_context: related lists filter, order and limit (where / orderBy / limit) with the render-service reader #37203.
  • Dev flag, neither real door supplies queryableFieldsOf: on real doors the fallback decides (served, not withheld, no maskingRule). That is the fallback the getQueryableFields contract and ADR D3 name, and it covers the card's "ordinary caller". A field the security answer excludes but the fallback admits (an agent acting for a person, a computed field reading a hidden one) still reaches the engine guard, which refuses the whole call: fail-closed, and against D3's "that refusal is never reached". Escalated to the seat: the door card (packages/runtime/src/domains/mcp.ts#recordContextMembers, packages/mcp/src/stdio-data-bridge.ts) has no carrier yet and needs one.
  • Dev flag, triage row 7154563681 (a related child this caller is not served is left out) implemented and reverted: answered, the tree at this head still refuses and the PR body says so. Escalated to the seat: the PR body says Fixes #37203, and the card's row is unchecked, so the row needs its own card before the merge closes this one.
  • Dev flag, Studio does not offer the three keys: answered, carried by 记录 AI 问询 7:在 Studio 里编辑资料包(ai_context 表单与作者界面) #37143 (note 7168171718).
  • Dev flag, RecordContextNoteKind prose says a cut "at the row cap": see N1.
  • Dev flag, a door page cap below limit + 1: see N2.
  • Dev flag, the baseline ledger grew: answered in ①.
  • Dev flag, stale PR body: answered, the body at this head names aa76b901b, 96 tests and the revert.
  • Dev flag, commit trailers: not a contract matter; the lane seat's.

④ Design judgment

packages/spec/src/ai/ai-context.zod.ts, against ADR-0160 D1 (second amendment) and its first consumer, executeGetRecordContext: the schema holds, with one hole.

S1 (should-fix) — aiContextWhereFields stops walking at depth 32, while checkRelatedWhere and FilterConditionSchema admit any nesting. A where nested deeper than 32 combinators parses, and the fields it names below that depth are in no list: the service does not judge them (neither "the child lacks it" nor "the caller cannot query on it"), the lint rule does not report them, and the query still runs with them. With the security plugin the engine guard then refuses the whole call for a caller who cannot query on such a field, which D3 says never happens; an unknown field reaches the engine. The two walks of one tree must agree: refuse nesting past a bound at parse (row 11 invites one, "refused at parse like the pack's other bounds"), or drop the cap. Pin the boundary by test.

packages/services/service-record-context/src/record-context-tools.ts and door.ts, sentence by sentence against D3: one capped query; the link filter joined with $and (a top-level $or in where cannot reach another root); orderBy passed; limit + 1 probe and the cut stated at plan.cap; a field the published definition lacks leaves the section out and states nothing; a field the caller cannot query on drops the section with the one statement and is never named; a throwing probe drops the section. The door answer path requires the field to be served as well as queryable. All agree with the contract. One case is not judged:

S2 (should-fix) — an orderBy on a field its author declared sortable: false is not judged anywhere. The stdio door's query refuses it before the engine (unofferedSortRefusal, INVALID_SORT, "Query parameter 'orderBy' sorts by ..."), and the executor does not catch it, so such a pack validates clean and then fails every call for every caller, with an error that blames a parameter the caller never sent. It is an author defect, and ADR D1 puts author defects on author surfaces while the answer states nothing. Report it in validate-ai-context.ts (and leave the section out in the executor, as for a field the child lacks), or have the seat rule it out of this card with a follow-up. Read on the stdio door only; the HTTP door's verdict was not read, so the parity line may also be at stake.

packages/lint/src/validate-ai-context.ts: extends the #37176 rule, reads the same aiContextWhereFields as the service, reports at related[i].where and related[i].orderBy[k].field, and its message matches what the service does (the list is left out). Agrees with D1, subject to S1 and S2.

Nits, none affecting correctness on the in-tree doors:

  • N1 (nit) — RecordContextNoteKind's doc line (packages/spec/src/ai/record-context-tools.zod.ts, outside the diff) still says related_truncated is a cut "at the row cap"; it now also fires at limit. Follow-up card.
  • N2 (nit) — ADR D1 and point 14 say a door whose own page cap is below a parsed limit cuts there "and the cut is stated". The executor cannot see such a cut (it compares against plan.cap), and door.ts does not say what a door owes. The stdio door passes limit through, so nothing in the tree reaches it as read; the HTTP bridge's cap was not read. Follow-up card.
  • N3 (nit) — AiContextRelatedWhere is typed as the whole FilterCondition, wider than the admitted subset, so the type admits $not and the others that parse refuses. Accepted deviation.
  • N4 (nit) — the limit describe reads "(at most 20, the default)"; the default is the row cap, which is the same number, but the sentence reads as if 20 were limit's default value. Accepted deviation.
  • N5 (nit) — no test pins an orderBy on a registry-injected field (created_at), the likely order for "the latest rows". Whether the lint field map and the published definition both carry it was not established by reading. Follow-up card.

Implemented-by: claude/issue-37203-related-where-orderby-limit
Reviewed-by: session_01Utp6CYtTDvfPQDzMbZnN5X

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

席位核对

Head-sha: aa76b901be
REWORK — L1, seat repo:objectstack#5: the two should-fix findings of contract record 7177225249 are fixed in this PR before landing; the rest of L1 reads clean.

  1. Shape: open draft against main; Fixes #37203 stands: the reverted triage row (7154563681), the where parity case and the doors' missing queryableFieldsOf are carried by 37203 跟进:get_record_context 无权的关联子对象改为省略、真实通道交出可查询字段,并补筛选排序的双通道比对 #37361, nested under ai_context: related lists filter, order and limit (where / orderBy / limit) with the render-service reader #37203, so merging still delivers the card as now scoped. l1-face CLEAN.
  2. Owed in this PR: S1 (the aiContextWhereFields walk stops at depth 32 while parse admits any nesting — bound the nesting at parse or drop the cap, pinned by a test) and S2 (an orderBy on a sortable: false field is judged nowhere and the stdio door's INVALID_SORT refuses the whole call — report it at validate and leave the section out at call time, pinned by a test; read the HTTP door too). The same reviewer reads the delta.
  3. Gates: check-runs at aa76b901be: 62 success, 12 expected skip, 0 failed, 0 pending; Lint & Repo Gates and TypeScript Type Check success. Changeset and the generated ai-context.mdx rows read against the diff: true.
  4. Accepted deviations: contract nits N3 (AiContextRelatedWhere type wider than parse) and N4 (the limit describe wording).
  5. Out of scope and where it went: N1 (related_truncated doc line), N2 (a door-side page cap the executor cannot see) and N5 (orderBy on a registry-injected field) go to 37203 跟进:get_record_context 无权的关联子对象改为省略、真实通道交出可查询字段,并补筛选排序的双通道比对 #37361 or a sibling follow-up; Studio controls stay with 记录 AI 问询 7:在 Studio 里编辑资料包(ai_context 表单与作者界面) #37143.
  6. Landing terms: ungoverned, default tier; Clause-②: yes with a published schema, so a same-head at-tier PASS with S1 and S2 closed is owed before the area lands it.

…st ordered by a field not offered as a sort

S1: AI_CONTEXT_WHERE_MAX_DEPTH (32) bounds $and / $or nesting in a related
list's where at parse, and aiContextWhereFields walks to exactly that depth,
so every field of a where that parsed is judged by the render service and
the author surfaces.

S2: an orderBy field the child's sortability projection calls unsortable (a
formula, or sortable: false) is an author defect: get_record_context leaves
the section out and states nothing, instead of the doors' INVALID_SORT
refusing the whole call, and validateAiContext reports it as the new warning
ai-context-sort-field-unsortable.

Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
Co-authored-by: Claude <noreply@anthropic.com>
…vers line within the one-line bound

Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head bb0107c · 2026-11-26T00:44Z

The seat runs the at-tier contract review of this head through an isolated sub-agent; L1 is the seat's own.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: bb0107ccadaab70025c410545408414395527a26
Local-runs: none
Scope: packages/spec/src/ai/ai-context.zod.ts + packages/services/service-record-context/src/record-context-tools.ts, packages/services/service-record-context/src/door.ts, packages/lint/src/validate-ai-context.ts, packages/lint/src/rule-explanations.ts, packages/lint/src/index.ts

Delta review of the round on aa76b901be459a8271b412ad9fcb099024a7fb33. Inputs read: card #37203 with its comments, the delta report among them (7179036175); the PR body at this head; the delta aa76b901b..bb0107cca (13 files); the check-runs on this head (no failure; every required run success or skipped). Read to judge, not reviewed: packages/spec/src/api/sortability.zod.ts#resolveObjectSortability, packages/metadata-protocol/src/protocol-query-validation.ts (assertSortFieldsExist, assertSortFieldsAreOffered, UNMATERIALIZED_SORT_TYPES), packages/mcp/src/stdio-data-bridge.ts#unofferedSortRefusal, packages/spec/src/data/search-fields.ts#SEARCH_VIRTUAL_TYPES. The sections below judge the whole PR at this head; what the earlier round settled and the delta did not touch is carried.

① Derived judgments

  • Carried from the earlier round, unchanged by the delta: related[] widened by the optional where, orderBy and limit; where a strict subset of the object filter form; limit bounded by the one number AI_CONTEXT_MAX_RELATED_ROWS; the aliases and guidance.filter text; the additive door members; the unchanged read set. All right.
  • New in the delta: where refuses $and / $or nested more than AI_CONTEXT_WHERE_MAX_DEPTH (32) lists deep. It narrows only what the earlier head of this same PR admitted, which was never published. Right: ADR-0160 row 11 invites the bound, "refused at parse like the pack's other bounds".
  • New public export AI_CONTEXT_WHERE_MAX_DEPTH in @objectstack/spec/ai; api-surface and export-origins moved with it. Additive.
  • New lint rule id ai-context-sort-field-unsortable (a warning) and its exported constant AI_CONTEXT_SORT_FIELD_UNSORTABLE. It can fire only on a pack that carries orderBy, which no pack on main can. Right.
  • The executor now leaves out, silently and for every caller, a related section whose orderBy names a field the child's sortability projection calls unsortable. Before the delta both doors refused that call whole. Right: an author defect, treated as the "field the definition lacks" arm is.
  • @objectstack/lint and @objectstack/service-record-context now import resolveObjectSortability from @objectstack/spec/api. Both already depend on the spec package; type checks are green.

② Semver level

minor on @objectstack/spec, @objectstack/service-record-context and @objectstack/lint, unchanged and still right: the delta adds one export and one rule id and removes nothing published. The changeset body now states the nesting bound and the unsortable-order rule. Check Changeset is success.
Clause-②: yes. The line stands in the PR body and in the changeset body, with no arm.

③ Boundary flags

  • SQL push-down: holds. The delta adds no read: the sortability verdict is computed from the published definition the executor already holds, and an unsortable order skips the query.
  • open_questions: none in the delta report.
  • Dev flag, S2 covers a formula as well as sortable: false: answered and accepted, see ④.
  • Dev flag, packages/lint/src/index.ts and rule-explanations.ts join the touched files: answered, they are the rule's wiring and are in Scope above.
  • Dev flag, N1, N2 and N5 not taken, carried by 37203 跟进:get_record_context 无权的关联子对象改为省略、真实通道交出可查询字段,并补筛选排序的双通道比对 #37361: accepted as carried.
  • Dev flag, PR refactor(spec)!: rename the Studio helper defineForm to defineMetadataForm and its modules to *.metadata-form.ts #37366 conflicts in the generated packages/spec/export-origins/ai.json: the lane seat's; whichever lands second regenerates the file.
  • Dev flags on push order (a push not gated on its overlap check; a push before the whole lint package ran) and commit trailers: not contract matters; the lane seat's. CI on this head is green.
  • Still escalated to the seat from the earlier round, and not answered by this delta: (1) the card's stdio/HTTP parity line has no where-pack case and needs a card; (2) neither real door supplies queryableFieldsOf, so a caller the security answer excludes but the fallback admits still gets a whole-call refusal from the engine guard, and that door card needs a carrier; (3) the PR body says Fixes #37203 while triage row 7154563681 is unchecked and not in this PR, so the row needs its own card before the merge closes this one.

④ Design judgment

S1: closed
S2: closed

packages/spec/src/ai/ai-context.zod.ts. checkRelatedWhere carries a depth that counts the $and / $or lists a condition sits beneath, and refuses a list that would put a condition at depth 33. aiContextWhereFields walks conditions down to depth 32 by the same constant and skips only members at depth 33, which parse has already refused. Read side by side, the two walks agree at the boundary: every field of a where that parsed is listed. The test pins 32 accepted, with the innermost field named, and 33 refused; the report's ablation of the bound went red.

packages/services/service-record-context/src/record-context-tools.ts. An orderBy field with sortable === false in resolveObjectSortability(published definition) leaves the section out before the query, after the "definition lacks it" check and before the caller-specific check, so the answer is the same for every caller and states nothing. A where on such a field still reads, which is right: the doors' verdict is on the sort axis only.

The formula widening, against both doors' actual predicate. resolveObjectSortability answers sortable: false for two reasons: virtual-type (isVirtualSearchField, SEARCH_VIRTUAL_TYPES, today formula alone) and author-declared (the literal sortable: false). The stdio door refuses by that same function (unofferedSortRefusal: projection[f]?.sortable === false), so it refuses both reasons. The HTTP door refuses sortable: false by that same function (assertSortFieldsAreOffered) and a formula by UNMATERIALIZED_SORT_TYPES, today formula alone. So the executor's predicate is exactly what each door refuses, and the widening holds; judging sortable: false alone would have left a formula order refusing the whole call on both doors. No must-fix, no should-fix.

packages/lint/src/validate-ai-context.ts, rule-explanations.ts, index.ts. The rule reads the same projection as the executor and the doors, reports at related[i].orderBy[k].field, reports an unknown field as ai-context-field-unknown first and never both, and its message matches what the executor does. Its wiring matches its sibling ai-context-body-not-long-text site for site: the constant in validate-ai-context.ts, the re-export in index.ts, the explanation and its RULE_EXPLANATIONS entry. The explanation's covers length pin is green on this head.

Tried and not broken: a pack with both an unknown and an unsortable order field (left out by the first check); an order on id (the projection answers sortable); a where-only entry (no sortability read); a lint run over array-shaped or map-shaped fields (the projection's reader takes both).

Nits, none affecting correctness on the in-tree doors:

Implemented-by: claude/issue-37203-related-where-orderby-limit
Reviewed-by: session_01Utp6CYtTDvfPQDzMbZnN5X

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

席位核对

Head-sha: bb0107ccadaab70025c410545408414395527a26
ACCEPT — L1, seat repo:objectstack#5

  1. Shape: open draft against main, 23 files, +1092/−52. Fixes #37203 stands. The reverted triage row (7154563681), the stdio/HTTP where parity case and the doors' missing queryableFieldsOf are carried by 37203 跟进:get_record_context 无权的关联子对象改为省略、真实通道交出可查询字段,并补筛选排序的双通道比对 #37361, nested under ai_context: related lists filter, order and limit (where / orderBy / limit) with the render-service reader #37203, so merging still delivers the card as now scoped.
  2. Rework closed (contract record 7179109796):
    • S1: AI_CONTEXT_WHERE_MAX_DEPTH (32) bounds nesting at parse, and aiContextWhereFields walks the same constant. The two agree at the boundary, pinned at 32 and 33.
    • S2: an unsortable orderBy leaves the section out silently, before the query, by resolveObjectSortability. The new lint rule ai-context-sort-field-unsortable is wired site for site like ai-context-body-not-long-text.
    • The declared widening to formula/virtual fields holds on both doors. stdio refuses by the same projection. HTTP refuses sortable: false by the projection and formula by UNMATERIALIZED_SORT_TYPES.
    • Three ablations, each red.
  3. Gates: check-runs at bb0107ccad: 62 success, 12 expected skip, 0 failed, 0 pending.
  4. Accepted deviations: the formula/virtual widening (above), and contract nits N3, N4 and N8.
  5. Out of scope and where it went:
  6. Landing terms: ungoverned, default tier, Clause-②: yes. L2 at CONTRACT_REVIEW_TIER: PASS, comment 7179109796, same head, no must-fix, no should-fix. The area lands it.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 26, 2026 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation protocol:ai size/xl tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ai_context: related lists filter, order and limit (where / orderBy / limit) with the render-service reader

2 participants